﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.Unity;

namespace HMIS.MVC.CommonSupport
{
    public class UnityControllerFactory : DefaultControllerFactory
    {
        private readonly IUnityContainer container;

        public UnityControllerFactory(IUnityContainer container)
        {
            //要做异常处理
            this.container = container;
        }
        protected override IController GetControllerInstance(Type controllerType)
        {
            //这里把Controller实例注册到了unity容器
            IController icontroller = container.Resolve(controllerType) as IController;
            return icontroller;
        }
    }
}
